package com.ruoyi.web.controller.system;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.TrainGrade;
import com.ruoyi.system.service.ITrainGradeService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 培训考核Controller
 * 
 * @author ruoyi
 * @date 2023-05-12
 */
@Controller
@RequestMapping("/system/grade")
public class TrainGradeController extends BaseController
{
    private String prefix = "system/grade";

    @Autowired
    private ITrainGradeService trainGradeService;

    @RequiresPermissions("system:grade:view")
    @GetMapping()
    public String grade()
    {
        return prefix + "/grade";
    }

    /**
     * 查询培训考核列表
     */
    @RequiresPermissions("system:grade:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TrainGrade trainGrade)
    {
        startPage();
        List<TrainGrade> list = trainGradeService.selectTrainGradeList(trainGrade);
        return getDataTable(list);
    }

    /**
     * 导出培训考核列表
     */
    @RequiresPermissions("system:grade:export")
    @Log(title = "培训考核", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TrainGrade trainGrade)
    {
        List<TrainGrade> list = trainGradeService.selectTrainGradeList(trainGrade);
        ExcelUtil<TrainGrade> util = new ExcelUtil<TrainGrade>(TrainGrade.class);
        return util.exportExcel(list, "培训考核数据");
    }

    /**
     * 新增培训考核
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存培训考核
     */
    @RequiresPermissions("system:grade:add")
    @Log(title = "培训考核", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TrainGrade trainGrade)
    {
        return toAjax(trainGradeService.insertTrainGrade(trainGrade));
    }

    /**
     * 修改培训考核
     */
    @RequiresPermissions("system:grade:edit")
    @GetMapping("/edit/{tgId}")
    public String edit(@PathVariable("tgId") Long tgId, ModelMap mmap)
    {
        TrainGrade trainGrade = trainGradeService.selectTrainGradeByTgId(tgId);
        mmap.put("trainGrade", trainGrade);
        return prefix + "/edit";
    }

    /**
     * 修改保存培训考核
     */
    @RequiresPermissions("system:grade:edit")
    @Log(title = "培训考核", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TrainGrade trainGrade)
    {
        return toAjax(trainGradeService.updateTrainGrade(trainGrade));
    }

    /**
     * 删除培训考核
     */
    @RequiresPermissions("system:grade:remove")
    @Log(title = "培训考核", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(trainGradeService.deleteTrainGradeByTgIds(ids));
    }

    /**
     * 转正
     */
    @RequiresPermissions("system:grade:toEmployee")
    @Log(title = "培训考核", businessType = BusinessType.UPDATE)
    @RequestMapping( "/toEmployee")
    @ResponseBody
    public AjaxResult toEmployee(Long employeeId)
    {
        return toAjax(trainGradeService.toEmployee(employeeId));
    }
}
